package com.atguigu.paymentdemo.uitl;

import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;


/**
 * 将响应来的参数转化为字符串
 */

public class HttpUtils {

    public static String readData(HttpServletRequest request){
        BufferedReader br = null;
        try{
            StringBuilder result = new StringBuilder();
            br = request.getReader();

            String line ;
            while((line = br.readLine())!=null){
                if(result.length()>0) result.append("/n");
                result.append(line);
            }

            return result.toString();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if(br!=null){
                try {
                    br.close();
                } catch (IOException e) {
                    e.printStackTrace();//在命令行打印异常信息在程序中出错的位置及原因
                }
            }
        }

        return null;
    }
}
